/**
 * 值模型类
 */
import StandardClass from './StandardClass.js';
import TypeKind from '../enums/TypeKind.js';
import DomainProperty from './DomainProperty.js';

export default class ValueClass extends StandardClass {

    /**
     * @type {[DomainProperty]}
     */
    properties = [];

    constructor(packageName, simpleName) {
        super(TypeKind.VALUE, packageName, simpleName);
    }

    static of(object) {
        if (typeof object !== 'object') {
            return undefined;
        }
        let clazz = new ValueClass(object.packageName, object.simpleName);
        clazz.update(object);
        return clazz;
    }

    update(object) {
        super.update(object);
        if (typeof object === 'object') {
            if (object.properties) {
                this.properties = object.properties.map(property => {
                    return DomainProperty.of(property);
                });
            }
        }
        return this;
    }

    clone() {
        return ValueClass.of(this);
    }

    getPropertyById(id) {
        return this.properties.find(property => property.id === id);
    }

}
